package com.example.lenovo.downloaddemo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.example.lenovo.downloaddemo.R;
import com.example.lenovo.downloaddemo.bean.ProductBean;
import com.example.lenovo.downloaddemo.http.AppConfig;
import com.example.lenovo.downloaddemo.http.okhttp.utils.AppContext;
import com.example.lenovo.downloaddemo.http.okhttp.utils.CommonUtils;
import com.example.lenovo.downloaddemo.util.TextStyleLanguage;
import com.squareup.picasso.Picasso;

import java.util.List;

public class MoreAdapter extends BaseAdapter {
    private Context context;
    private List<ProductBean.DataBean.GoodsListBean> data;

    public MoreAdapter(Context context,List<ProductBean.DataBean.GoodsListBean> data){
        this.context=context;
        this.data=data;

    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder holder=null;
        if(view==null){
            holder=new ViewHolder();
            view=LayoutInflater.from(AppContext.getInstance()).inflate(R.layout.item_more,null);
            holder.iv_More=(ImageView) view.findViewById(R.id.iv_more);
            holder.name_More=(TextView) view.findViewById(R.id.name_More);
            holder.layout=(LinearLayout) view.findViewById(R.id.more_lin);
            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }

        if(!TextStyleLanguage.isEngLish()){
            holder.name_More.setText(data.get(i).getGood_name());
        }else{
            holder.name_More.setText(data.get(i).getGood_name_en());
        }
        int width = CommonUtils.getScreenWidth(AppContext.getInstance());
        int height=CommonUtils.getScreenHeight(AppContext.getInstance())/10;
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height);
        holder.layout.setLayoutParams(lp);
        Picasso.with(context).load(AppConfig.IP+data.get(i).getGood_pic())
                .into(holder.iv_More);
        return view;
    }
    static  class ViewHolder{
        ImageView iv_More;
        TextView name_More;
        LinearLayout layout;
    }
}
